import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    { path: '/', redirect: '/login' },
    {
      path: '/manager',
      component: () => import('@/views/Manager.vue'),
      children: [
        { path: 'home', meta: { name: '系统首页' }, component: () => import('@/views/manager/Home.vue'),  },
        { path: 'admin', meta: { name: '管理员信息' }, component: () => import('@/views/manager/Admin.vue'), },
        { path: 'user', meta: { name: '普通用户信息' }, component: () => import('@/views/manager/User.vue'), },
        { path: 'notice', meta: { name: '系统公告' }, component: () => import('@/views/manager/Notice.vue'), },
        { path: 'person', meta: { name: '个人资料' }, component: () => import('@/views/manager/Person.vue'), },
        { path: 'password', meta: { name: '修改密码' }, component: () => import('@/views/manager/Password.vue'), },
        { path: 'category', meta: { name: '商品分类' }, component: () => import('@/views/manager/Category.vue'), },
        { path: 'goods', meta: { name: '商品信息' }, component: () => import('@/views/manager/Goods.vue'), },
        { path: 'banner', meta: { name: '轮播图信息' }, component: () => import('@/views/manager/Banner.vue'), },
        { path: 'collect', meta: { name: '商品收藏' }, component: () => import('@/views/manager/Collect.vue'), },
        { path: 'orders', meta: { name: '订单信息' }, component: () => import('@/views/manager/Orders.vue'), },
        { path: 'comment', meta: { name: '商品评价' }, component: () => import('@/views/manager/Comment.vue'), },
      ]
    },
    {
      path: '/front',
      component: () => import('@/views/Front.vue'),
      children: [
        { path: 'home', component: () => import('@/views/front/Home.vue'),  },
        { path: 'person', component: () => import('@/views/front/Person.vue'),  },
        { path: 'password', component: () => import('@/views/front/Password.vue'),  },
        { path: 'goodsDetail', component: () => import('@/views/front/GoodsDetail.vue'),  },
        { path: 'goods', component: () => import('@/views/front/Goods.vue'),  },
        { path: 'userCollect', component: () => import('@/views/front/UserCollect.vue'),  },
        { path: 'address', component: () => import('@/views/front/Address.vue'),  },
        { path: 'cart', component: () => import('@/views/front/Cart.vue'),  },
        { path: 'orders', component: () => import('@/views/front/Orders.vue'),  },
        { path: 'userComment', component: () => import('@/views/front/UserComment.vue'),  },
        { path: 'notice', component: () => import('@/views/front/Notice.vue'),  },
      ]
    },
    { path: '/login', component: () => import('@/views/Login.vue') },
    { path: '/register', component: () => import('@/views/Register.vue') },
    { path: '/404', component: () => import('@/views/404.vue') },
    { path: '/:pathMatch(.*)', redirect: '/404' }
  ]
})

router.beforeEach(() => {
  window.scrollTo({top: 0, behavior: "smooth" })
})

export default router
